package com.java.yz.day08.ketang;
/*
    多态中的类型转化异常  （ClassCastException）
 */
class Person{
    public void eat(){
        System.out.println("吃的");
    }
}
class nanPerson extends Person{
    @Override
    public void eat() {
        System.out.println("吃米饭");
    }
}
class beiPerson extends Person{
    @Override
    public void eat() {
        System.out.println("吃馒头");
    }
}
public class DouTaiDemo5 {
    public static void main(String[] args) {
        Person person = new nanPerson();
        nanPerson nanperson = (nanPerson) person;
        //这样就向下转型了

        //beiPerson beiperson = (beiPerson) person;
/*会报这个错
Exception in thread "main" java.lang.ClassCastException: class com.java.yz.day08.ketang.nanPerson cannot be cast to class com.java.yz.day08.ketang.beiPerson (com.java.yz.day08.ketang.nanPerson and com.java.yz.day08.ketang.beiPerson are in unnamed module of loader 'app')
at com.java.yz.day08.ketang.DouTaiDemo5.main(DouTaiDemo5.java:28)
*/
        //jvm运行的时候会先检测栈中的变量类型和堆内存中的类型是否是继承关系或者是否一样，如果两个条件都不满足，那么就会报错
    }
}
